*** Sexism and Voting for Women Candidates - BJPS replication do-files
*** Australia

log using "C:\Users\a15014rs\Dropbox\Sexism and Candidates\Analysis\BJPS replication files\Australia_log_file.log", replace

** Recoding and merging data files

cd "C:\Users\a15014rs\Dropbox\Sexism and Candidates\Data\Australia"

import excel "Australia_candidates.xlsx", firstrow clear

** drop variables not required
drop StateAb CandidateID Surname GivenNm Link

** keep main parties
keep if PartyNm=="Liberal"|PartyNm=="Country Liberals (NT"|PartyNm=="Liberal National Party of Queensland"|PartyNm=="National Party"| ///
	PartyNm=="The Nationals"|PartyNm=="Australian Labor Party"|PartyNm=="Australian Labor Party (Northern Territory) Branch"|PartyNm=="Labor"| ///
	PartyNm=="The Greens"|PartyNm=="The Greens (VIC)"|PartyNm=="The Greens (WA)"

** candidate gender
gen candidate_gender=1 if Gender=="F"
replace candidate_gender=0 if Gender=="M"
label define genderlab 0 "men" 1 "women"
label values candidate_gender genderlab
drop Gender

** distance from the winner in 2016
destring ElectionVoteShare, dpcomma ignore("%" "#N/D" ",,,") generate(voteshare2016)
gen voteshare2016_v2=voteshare2016/100
drop ElectionVoteShare voteshare2016
rename voteshare2016_v2 voteshare2016

egen max_share = max(voteshare2016), by(DivisionID)
gen winner2016 = 1 if max_share==voteshare2016
replace winner2016 = 0 if winner2016!=1

gen distance=max_share-voteshare2016
/* give median distance if party did not stand in 2016 */
/* give median distance for new constituencies */
tabstat distance, stats(median)
replace distance=15.85 if distance==.

*set previous vote share to zero if they did not stand in 2016*
replace voteshare2016=0 if voteshare2016==.

drop max_share

** winner 2019
destring VoteShare, ignore("%" ",") generate(voteshare2019)
gen voteshare2019_v2=voteshare2019/100
drop voteshare2019
rename voteshare2019_v2 voteshare2019
egen max_share = max(voteshare2019), by(DivisionID)
gen winner2019 = 1 if max_share==voteshare2019
replace winner2019 = 1 if max_share==voteshare2019
replace winner2019 = 0 if winner2019==.

** descriptives candidates (Table 4)
tab candidate_gender
replace Incumbent="Y" if Incumbent=="y"
tab Incumbent candidate_gender, row
tab winner2019 candidate_gender, row
ttest distance, by(candidate_gender)
tab candidate_gender if PartyNm=="Liberal"|PartyNm=="Country Liberals (NT"| ///
	PartyNm=="Liberal National Party of Queensland"|PartyNm=="National Party"|PartyNm=="The Nationals"
tab candidate_gender if PartyNm=="Australian Labor Party"| ///
	PartyNm=="Australian Labor Party (Northern Territory) Branch"|PartyNm=="Labor"
tab candidate_gender if PartyNm=="The Greens"|PartyNm=="The Greens (VIC)"|PartyNm=="The Greens (WA)"

** Women races
gen candidate_gender2=1 if candidate_gender==1 /*women*/
replace candidate_gender2=2 if candidate_gender==0 /*men*/
fre candidate_gender
egen women_race = min(candidate_gender2), by(DivisionID) /*minimum value within district*/
egen women_only = max(candidate_gender2), by(DivisionID) /*maximum value within district*/
codebook DivisionID
codebook DivisionID if women_race==2
codebook DivisionID if women_only==1


saveold "Australia_candidates_data.dta", replace

** Vote choice data
use "aes19_unrestricted.dta", clear

** recode division name for merging
rename CED_AEC DivisionID

** merge with candidates data
sort DivisionID

** merge with candidates data
joinby DivisionID using "Australia_candidates_data.dta"

** respondent vote choice
gen vote_choice=1 if B9_1==1&PartyNm=="Liberal"|PartyNm=="Country Liberals (NT)"| ///
	PartyNm=="Liberal National Party of Queensland"
replace vote_choice=1 if B9_1==2&PartyNm=="Australian Labor Party"| ///
	PartyNm=="Australian Labor Party (Northern Territory) Branch"|PartyNm=="Labor"
replace vote_choice=1 if B9_1==3&PartyNm=="National Party"|PartyNm=="The Nationals"
replace vote_choice=1 if B9_1==4&PartyNm=="The Greens"|PartyNm=="The Greens (VIC)"|PartyNm=="The Greens (WA)"
replace vote_choice=0 if vote_choice==.
replace vote_choice=. if B9_1==6|B9_1==999

saveold "Australia_data.dta", replace

************************************************************************************************************************

** Analysis

cd "C:\Users\a15014rs\Dropbox\Sexism and Candidates\"

use "Data\Australia\Australia_data.dta", clear

* Create variable for women races
fre candidate_gender
*egen women_race = min(candidate_gender2), by(DivisionID)
*egen women_only = max(candidate_gender2), by(DivisionID)
gen sample_races=1 if women_race==1&women_only==2
replace sample_races=0 if sample_races==.

codebook DivisionID if sample_races==1
**all-women races
codebook DivisionID if women_race==2
**all-male races
codebook DivisionID if women_only==1

** HOstile sexism - sample size
tab E9_1, missing
tab E9_2, missing
tab E9_3, missing

** Sexism measures (hostile only)
recode E9_1 (1=5) (2=4) (3=3) (4=2) (5=1) (999=.), generate(innocent)
recode E9_2 (1=5) (2=4) (3=3) (4=2) (5=1) (999=.), generate(appreciate)
recode E9_3 (1=5) (2=4) (3=3) (4=2) (5=1) (999=.), generate(control)

alpha innocent appreciate control /*0.829 */

* scale to range - 2 to +2 (positive values = high in sexism)
recode appreciate 1=-2 2=-1 3=0 4=1 5=2
recode control   1=-2 2=-1 3=0 4=1 5=2
recode innocent   1=-2 2=-1 3=0 4=1 5=2

* Create scale
* rowtotal 
egen hostile = rowtotal(innocent control appreciate), missing

* Recode -1 to +1 
gen hostile_rescale = hostile / 6

gen hostile_rescale2 = hostile_rescale+1

codebook ID if hostile_rescale2!=.

gen nothostile=1 if hostile_rescale<0
replace nothostile=0 if hostile_rescale>=0
gen hostile2=1 if hostile_rescale>0
replace hostile2=0 if hostile_rescale<=0

** Consolidate parties into four main parties
gen party_name="Liberal" if PartyNm=="Liberal"|PartyNm=="Country Liberals (NT)"| ///
	PartyNm=="Liberal National Party of Queensland"
replace party_name="National" if PartyNm=="National Party"|PartyNm=="The Nationals"
replace party_name="Labor" if PartyNm=="Australian Labor Party"| ///
	PartyNm=="Australian Labor Party (Northern Territory) Branch"|PartyNm=="Labor"
replace party_name="Greens" if PartyNm=="The Greens"|PartyNm=="The Greens (VIC)"|PartyNm=="The Greens (WA)"

** Non party identifiers
gen nonpartisan=1 if B1==6
replace nonpartisan=0 if nonpartisan==.&B1!=999

** Candidate party
gen party_candidate=1 if party_name=="Liberal"|party_name=="National"
replace party_candidate=2 if party_name=="Labor"
replace party_candidate=3 if party_name=="Greens"
label define partylab 1 "Liberal-National" 2 "Labor" 3 "Greens"
label values party_candidate partylab

** Respondent gender
gen female=1 if H1==2
replace female=0 if H1==1
label define femlab 0 "men" 1 "women"
label values female femlab

** Incumbent
gen incumbent=1 if Incumbent=="Y"
replace incumbent=0 if Incumbent=="N"
label define incumbentlab 0 "not incumbent" 1 "incumbent"
label values incumbent incumbentlab

save "Data\Australia_data_recoded.dta", replace

** define sample
gen fullsample=1 if vote_choice!=.&candidate_gender!=.&party_candidate!=.&incumbent!=.&distance!=.&hostile_rescale!=.
replace fullsample=0 if fullsample!=1

** identify respondents with all zeros on vote choice dependent var
clogit vote_choice i.candidate_gender if fullsample==1&sample_races==1 [pw=wt_pooled], group(ID) or
gen wanted=e(sample)
tab wanted

** Keep analytical sample
keep if wanted==1

** sample size
codebook ID

** Scale reliability for the analytical sample
alpha innocent control appreciate


** Models
** Voting for female candidates - with and without controls
quietly clogit vote_choice i.candidate_gender if fullsample==1&sample_races==1 [pw=wt_pooled], group(ID) or
outreg using "Output\BJPS resubmission\Table 6 Australia.doc", replace se or starlevels(10 5 1)
margins, dydx(candidate_gender) post
est store model_1
quietly clogit vote_choice i.candidate_gender i.party_candidate i.incumbent c.distance ///
	if fullsample==1&sample_races==1 [pw=wt_pooled], group(ID) or
outreg using "Output\BJPS resubmission\Table 6 Australia.doc", merge se or starlevels(10 5 1)
margins, dydx(candidate_gender) post
est store model_2
coefplot (model_1, label("M1 - Without controls")) (model_2, label("M2 - With controls")), title("Australia") ///
	ytitle("AME voting for female candidate") ylabel("") xline(0) saving("Output\BJPS resubmission\Australia_table6", replace)

** Voting for female candidates by hostile sexism (controlling for sexism*party)

set more off
clogit vote_choice i.candidate_gender##c.hostile_rescale2 i.party_candidate i.incumbent c.distance ///
	if fullsample==1&sample_races==1 [pw=wt_pooled], group(ID) or
outreg using "Output\BJPS resubmission\Table 7 Australia.doc", replace se or ctitles("", " c. gender*sexism") starlevels(10 5 1)
clogit vote_choice i.candidate_gender##c.hostile_rescale2 i.party_candidate##c.hostile_rescale2 i.incumbent c.distance ///
	if fullsample==1&sample_races==1 [pw=wt_pooled], group(ID) or
outreg using "Output\BJPS resubmission\Table 7 Australia.doc", merge se or ctitles("", " c. gender*sexism") starlevels(10 5 1)

** Robustness checks
* For women and men

clogit vote_choice i.candidate_gender##c.hostile_rescale2 i.party_candidate##c.hostile_rescale2 i.incumbent c.distance ///
	if fullsample==1&female==1&sample_races==1 [pw=wt_pooled], group(ID) or
outreg using "Output\BJPS resubmission\Robustness checks\gender Australia.doc", replace se or ctitles("", "women") starlevels(10 5 1)
clogit vote_choice i.candidate_gender##c.hostile_rescale2 i.party_candidate##c.hostile_rescale2 i.incumbent c.distance ///
	if fullsample==1&female==0&sample_races==1 [pw=wt_pooled], group(ID) or
outreg using "Output\BJPS resubmission\Robustness checks\gender Australia.doc", merge se or ctitles("", "men") starlevels(10 5 1)

** For partisans and non-partisans
clogit vote_choice i.candidate_gender##c.hostile_rescale2 i.party_candidate##c.hostile_rescale2 i.incumbent c.distance ///
	if fullsample==1&sample_races==1&nonpartisan==0 [pw=wt_pooled], group(ID) or
outreg using "Output\BJPS resubmission\Robustness checks\partisanship Australia.doc", replace se or ctitles("", " c. gender*sexism") starlevels(10 5 1)
clogit vote_choice i.candidate_gender##c.hostile_rescale2 i.party_candidate##c.hostile_rescale2 i.incumbent c.distance ///
	if fullsample==1&sample_races==1&nonpartisan==1 [pw=wt_pooled], group(ID) or
outreg using "Output\BJPS resubmission\Robustness checks\partisanship Australia.doc", merge se or ctitles("", " c. gender*sexism") starlevels(10 5 1)

** By party
clogit vote_choice i.candidate_gender##c.hostile_rescale2 i.party_candidate##c.hostile_rescale2 i.incumbent c.distance ///
	if fullsample==1&sample_races==1&B1==1|B1==3 [pw=wt_pooled], group(ID) or
outreg using "Output\BJPS resubmission\Robustness checks\party Australia.doc", replace se or ctitles("", " c. Liberal-National identifiers") starlevels(10 5 1)
clogit vote_choice i.candidate_gender##c.hostile_rescale2 i.party_candidate##c.hostile_rescale2 i.incumbent c.distance ///
	if fullsample==1&sample_races==1&B1==2 [pw=wt_pooled], group(ID) or
outreg using "Output\BJPS resubmission\Robustness checks\party Australia.doc", merge se or ctitles("", " c. Labor identifiers") starlevels(10 5 1)

** Using "women seek to gain power by getting control over men" (consistent across countries)
clogit vote_choice i.candidate_gender##c.control i.party_candidate##c.hostile_rescale2 i.incumbent c.distance ///
	if fullsample==1&sample_races==1 [pw=wt_pooled], group(ID) or
outreg using "Output\BJPS resubmission\Robustness checks\control item Australia.doc", replace or

* Vote share at previous election as a control
** Correlation between distance from winner and vote share = -0.8616
clogit vote_choice i.candidate_gender i.party_candidate i.incumbent c.voteshare2016 ///
	if fullsample==1&sample_races==1 [pw=wt_pooled], group(ID) or
outreg using "Output\BJPS resubmission\Robustness checks\vote share control Australia.doc", replace se or starlevels(10 5 1)
clogit vote_choice i.candidate_gender##c.hostile_rescale2 i.party_candidate i.incumbent c.voteshare2016 ///
	if fullsample==1&sample_races==1 [pw=wt_pooled], group(ID) or
outreg using "Output\BJPS resubmission\Robustness checks\vote share control Australia.doc", merge se or starlevels(10 5 1)
clogit vote_choice i.candidate_gender##c.hostile_rescale2 i.party_candidate##c.hostile_rescale2 i.incumbent c.voteshare2016 ///
	if fullsample==1&sample_races==1 [pw=wt_pooled], group(ID) or
outreg using "Output\BJPS resubmission\Robustness checks\vote share control Australia.doc", merge se or starlevels(10 5 1)

** Table 3 for analytical sample only
collapse hostile2 nothostile [iw=wt_pooled], by(ID)

tab nothostile
tab hostile2

** TURNOUT

use "Data\Australia_data_recoded.dta", clear

** 95% turnout in the weighted sample
** Abstainers (includes informal votes)
gen abstain=1 if B9_1==6
replace abstain=0 if B9_1!=6&B9_1!=999

tab abstain [iw=wt_pooled]

** Co-partisan
gen copartisan=1 if party_candidate==1&B1==1|party_candidate==1&B1==3|party_candidate==2&B1==2| ///
	party_candidate==4&B1==4
replace copartisan=0 if copartisan==.

drop if copartisan==0

** Age
gen age=AGE
replace age=. if age==999

** Education
* AES provides age left secondary school and post-school qualifications
gen educ=0 if G3==1
replace educ=1 if G3==2|G3==3
replace educ=2 if G3>=4&G3<=7
label define educlab 0 "no qualification since leaving school" 1 "Degree and postgraduate degrees" 2 "Other qualification"
label values educ educlab

** Employment status
gen employ=1 if G4==1|G4==2
replace employ=2 if G4==3|G4==4|G4==7
replace employ=3 if G4==5
replace employ=4 if G4==6
replace employ=5 if employ==96
label define employlab 1 "Employed" 2 "Unemployed" 3 "Retired" 4 "Student" 5 "Other"
label values employ employlab

** Income
gen income=J6
replace income=. if income==999

** Union membership
gen union=1 if G6==1
replace union=0 if G6==2

** Abstention model
** can't control for state because there is insufficient variation on abstention within some states - makes since given v low sample size
logit abstain c.hostile_rescale2##i.candidate_gender i.female i.educ c.age i.employ c.income c.distance i.incumbent ///
	i.union [pw=wt_pooled] if sample_races==1&copartisan==1 
outreg using "Output\BJPS resubmission\Table 8 Australia.doc", replace se or ctitles("", "Abstention") starlevels (10 5 1)
margins candidate_gender, at(hostile_rescale2=(0(1)2))
marginsplot, ytitle("Probability of abstaining") xtitle("") xlabel(0 "Not sexist (<1)" 1 "Neutral (1)" 2 "Sexist (>1)") ///
	title("Australia") saving("Output\BJPS resubmission\Australia_table8", replace)

** Robustness - by party
logit abstain c.hostile_rescale2##i.candidate_gender i.female i.educ c.age i.employ c.income c.distance i.incumbent ///
	i.union [pw=wt_pooled] if sample_races==1&copartisan==1&B1==1|B1==3 
outreg using "Output\BJPS resubmission\Robustness checks\party turnout Australia.doc", replace se or ctitles("", " c. Liberal-National identifiers") starlevels (10 5 1)
logit abstain c.hostile_rescale2##i.candidate_gender i.female i.educ c.age i.employ c.income c.distance i.incumbent ///
	i.union [pw=wt_pooled] if sample_races==1&copartisan==1&B1==2
outreg using "Output\BJPS resubmission\Robustness checks\party turnout Australia.doc", merge se or ctitles("", " c. Labor identifiers") starlevels (10 5 1)

** Robustness - using "women seek to gain power by getting control over men"
logit abstain c.control##i.candidate_gender i.female i.educ c.age i.employ c.income c.distance i.incumbent ///
	i.union [pw=wt_pooled] if sample_races==1&copartisan==1 
outreg using "Output\BJPS resubmission\Robustness checks\control turnout Australia.doc", replace se or ctitles("", "Abstention") starlevels (10 5 1)

** Controlling for previous vote share
logit abstain c.hostile_rescale2##i.candidate_gender i.female i.educ c.age i.employ c.income c.voteshare2016 i.incumbent ///
	i.union [pw=wt_pooled] if sample_races==1&copartisan==1 
outreg using "Output\BJPS resubmission\Robustness checks\vote share control turnout Australia.doc", replace se or ctitles("", "Abstention") starlevels (10 5 1)

** Abstention models
use "Data\Australia_data_recoded.dta", clear 

** 80% turnout in the weighted sample
** Abstainers
gen abstain=1 if B9_1==6
replace abstain=0 if B9_1!=6&B9_1!=999


** Abstainers versus voters on sexism
collapse abstain hostile_rescale [iw=wt_pooled], by(ID)
drop if hostile_rescale==.

gen nothostile=1 if hostile_rescale<0
replace nothostile=0 if hostile_rescale>=0
gen hostile2=1 if hostile_rescale>0
replace hostile2=0 if hostile_rescale<=0

tab abstain hostile2, row
tab abstain nothostile, row

log close













